package com.ruoyi.front;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableSupport;
import com.ruoyi.system.domain.SysAbout;
import com.ruoyi.system.domain.SysDoc;
import com.ruoyi.system.domain.SysNotice;
import com.ruoyi.system.domain.SysSite;
import com.ruoyi.system.service.ISysAboutService;
import com.ruoyi.system.service.ISysDocService;
import com.ruoyi.system.service.ISysNoticeService;
import com.ruoyi.system.service.ISysSiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

//搜索
@Controller
public class about extends BaseController {
    @Autowired
    private ISysAboutService iSysAboutService;
    @Autowired
    ISysSiteService iSysSiteService;
    @Autowired
    ISysNoticeService iSysNoticeService;
    @GetMapping({"/help.htm"})
    public String help(ModelMap modelMap, @RequestParam("id") long id)
    {
        getabout(modelMap);
        String about_content = iSysAboutService.selectSysAboutById(id).getContent();
        modelMap.put("about_content",about_content);
        modelMap.put("id",id);
        return "about";
    }
    @GetMapping({"/notice.htm"})
    public String notice(ModelMap modelMap, @RequestParam("id") long id)
    {
        getabout(modelMap);
        SysNotice sysNotice = iSysNoticeService.selectNoticeById(id);
        modelMap.put("notice",sysNotice);
        return "notice";
    }
    public  void getabout(ModelMap modelMap)
    {
        HashMap<String, List<SysAbout>> abouthash = new HashMap<String,List<SysAbout>>();
        List<SysAbout> tem1 = new ArrayList<SysAbout>();
        SysAbout  sysAbout = new SysAbout();
        sysAbout.setState(1);
        List<SysAbout> sysAboutList = iSysAboutService.selectSysAboutList(sysAbout);
        for(int i=0;i<sysAboutList.size();i++)
        {
            if (abouthash.containsKey(sysAboutList.get(i).getGroupname())) {
                abouthash.get(sysAboutList.get(i).getGroupname()).add(sysAboutList.get(i));
            } else {
                tem1.clear();
                tem1.add(sysAboutList.get(i));
                List<SysAbout> list = new ArrayList<SysAbout>(tem1);
                abouthash.put(sysAboutList.get(i).getGroupname(), list);
            }
        }
        modelMap.put("site",iSysSiteService.selectSysSiteList(new SysSite()).get(0));
        modelMap.put("about",abouthash);
    }
}
